# _*_ coding: UTF-8 _*_
# @Time     : 2021/4/29 下午 05:36
# @Author   : Li Jie
# @Site     : http://www.hzdledu.com/
# @File     : mainPage_001_enter_mall.py
# @Software : PyCharm

from selenium import webdriver
import unittest
import time


class MainPage_001_enter_mall(unittest.TestCase):
    def setUp(self) -> None:
        options = webdriver.ChromeOptions()
        # options.add_argument('--no-sandbox')  # 解决DevToolsActivePort文件不存在的报错
        # options.add_argument('--disable-dev-shm-usage')#overcome limited resource problems
        # options.add_argument('--disable-gpu')  # 谷歌文档提到需要加上这个属性来规避bug
        # options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度
        # options.add_argument('--headless')  # 浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
        # options.add_argument(r'--user-data-dir = /')
        #
        # self.driver = webdriver.Chrome(options=options)

        # self.driver = webdriver.Chrome()
        #设置chrome路径
        self.driver = webdriver.Chrome(
            r"C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe")
        self.url = "http://127.0.0.1:8080/shouan_insurance/shouan_index"
        self.driver.maximize_window()

    def test(self):
        self.driver.get(self.url)
        time.sleep(3)
        self.driver.find_element_by_link_text("保险商城").click()
        time.sleep(1)
        price = self.driver.find_element_by_xpath('//*[@id="backin"]/div[1]/table/tbody/tr/td['
                                                  '2]/div/div[3]/span[1]').text
        self.assertEqual('200', price)
        self.driver.find_element_by_xpath('//*[@id="backin"]/div[1]/table/tbody/tr/td[2]/div/div['
                                          '1]/button').click()
        time.sleep(1)

    def tearDown(self) -> None:
        self.driver.close()
